<template>
	<view class="content">
		<!-- 图片 -->
		<view>
			<view class="ipts">
				<view class="record">
					<view class="">
						<image src="/static/jilu.png" mode=""></image>
						<span>用户信息</span>
					</view>
				</view>
				<!-- 户号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>档案号</span>
					</view>
					<span class="place-class">A01978888888888</span>
				</view>
				
				<!-- 户主姓名 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>户主姓名</span>
					</view>
					<span class="place-class">孙铁镑</span>
				</view>
				
				<!-- 身份证号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>身份证号</span>
					</view>
					<span class="place-class">133026196600000000</span>
				</view>
				
				<!-- 联系方式 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>联系方式</span>
					</view>
					<view class="" style="display: flex;align-items: center;">
						<image src="/static/pagesB/tel.png" mode=""></image>
						<span class="place-class">13888888888</span>
					</view>
				</view>
				
				<!-- 地址 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>地址</span>
					</view>
					<span class="place-class">武强县街关镇康庄村81号</span>
				</view>
			</view>
			<!-- 第二块 -->
			<view class="ipts">
				<!-- 抄表日期 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>抄表日期</span>
					</view>
					<span class="place-class">2020.07.30</span>
				</view>
				
				<!-- 客户编号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>客户编号</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="324" />
				</view>
				
				<!-- 单位名称 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>单位名称</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="单位名称" />
				</view>
				
				<!-- 地址 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>地址</span>
					</view>
					<view class="" style="display: flex;align-items: center;">
						<input class="item-ipt" type="text" value="" placeholder="武强县东孙庄任庄村" />
						<image src="/static/pagesB/weizhi.png" mode=""></image>
					</view>
				</view>
				
				<!-- 流量编号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>流量编号</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="435435" />
				</view>
				
				<!-- 添加流量计照片 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>添加流量计照片</span>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-for="(i,index) in img1">
							<image class="form-img" :src="i" :key="index" @tap="seeimg(index)"></image>
							<image class="delet" src="/static/delet.png" mode="" @tap="deletImg(index)"></image>
						</view>
						<view class="add" @tap="choosefrom">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>
				
				<!-- 修正仪编号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>修正仪编号</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="324" />
				</view>
				
				<!-- 添加修正仪照片 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>添加修正仪照片</span>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-for="(i,index) in img2">
							<image class="form-img" :src="i" :key="index" @tap="seeimg2(index)"></image>
							<image class="delet" src="/static/delet.png" mode="" @tap="deletImg2(index)"></image>
						</view>
						<view class="add" @tap="choosefrom2">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>
				
				<!-- 上期读数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>上期读数</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="20" />
				</view>
				
				<!-- 本期读数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>本期读数</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="20" />
				</view>
				
				<!-- 本期实用数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>本期实用数</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="432W" />
				</view>
				
				<!-- 本期实用天数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>本期实用天数</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="20" />
				</view>
				
				<!-- 本期平均日用气量 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>本期平均日用气量</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="12" />
				</view>
				
				<!-- 本期单价 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>本期单价</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="20元/立方米" />
				</view>
				
				<!-- 本期气费 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>本期气费</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="230元" />
				</view>
				
			</view>
			
			<!-- 图片资料 -->
			<view class="ipts">
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>资料照片</span>
					</view>
					<view class="addform-items">
						<view class="" style="position: relative;" v-for="(i,index) in img3">
							<image class="form-img" :src="i" :key="index" @tap="seeimg3(index)"></image>
							<image class="delet" src="/static/delet.png" mode="" @tap="deletImg3(index)"></image>
						</view>
						<view class="add" @tap="choosefrom3">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>
			</view>
			<!-- 第四块 -->
			<view class="ipts">
				<!-- 平均气量 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>平均气量</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="454" />
				</view>
				
				<!-- 总费用 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>总费用</span>
					</view>
					<input class="item-ipt" type="text" value="" placeholder="43253元" />
				</view>
				
			</view>

			<!-- 跟踪记录 -->
			<view class="ipts">
				<!-- 历史安检 -->
				<view class="record">
					<view class="">
						<image src="/static/jilu.png" mode=""></image>
						<span>历史清零记录</span>
					</view>
					<view class="right">
							<input @input="searChange" v-model="searchIpt" type="text" value="" placeholder="请输入"
								placeholder-class="plac-class" />
							<image src="/static/search1.png" mode="" @click="searNum"></image>
					</view>
				</view>
				<!-- 联系人 -->
				<view class="liaison">
					<view class="left">
						<view class="shuxian"></view>
						<view class="name">李忠育</view>
						<view class="time">2020.07.24</view>
					</view>
					<view class="right">
						<image src="/static/pagesB/tel.png" mode=""></image>
						<view class="phone">13999999999</view>
						<image src="/static/xia.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<cpimg ref="cpimg" @result="cpimgOk" @err="cpimgErr" :number="1" :fixOrientation="true" :size="500"
			:maxWidth="800" :ql="0.7" type="url" />

	</view>
</template>

<script>
	import cpimg from "@/components/cpimg/cpimg.vue"
	import easySelect from '@/components/easy-select/easy-select'
	export default {
		components: {
			easySelect,
			cpimg
		},
		data() {
			return {
				news:[],
				index: 0,
				user: ['居民用户', '工商业用户'],
				ret: '',
				mysearchIpt: false,
				searchIpt: '',
				searchIpts: '',
				flag: true,
				token: '',
				last_check: {},
				user_info: {},
				textNumber: 0,
				// 品牌数组
				options: [],
				// 功率数组
				options1: [],
				// 品牌id
				brandId: '',
				// 功率id
				powerId: '',
				// 备注
				autoText: '',
				// 气表底数
				meter_base_num: '',
				// 默认显示品牌名
				brandName: '',
				// 默认显示功率
				powerName: '',
				// 气表照片地址
				img1: [],
				img2: [],
				img3: [],
				img4: [],
				// 是否安检
				isChecked: true,
				isCheckedNum: '',
				// 是否签收
				isChecked1: true,
				isCheckedNum1: '',
				// 是否派发
				isChecked2: true,
				isCheckedNum2: '',
				showRecord: true,
				marginBotton1: 100 + 'rpx',
				danger_id: ''
			}
		},
		onShow() {
		},
		onLoad() {
		},
		methods: {
			// 选择图片
			choosefrom() {
				if(this.img1.length<4){
					var _this = this
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							_this.img1.push(res.tempFilePaths[0])
							
						}
					})
				}else{
					uni.showToast({
						icon:'none',
						title:'上传已达到限制'
					})
				}
				
			},
			// 删除图片
			deletImg(index) {
				this.img1.splice(index,1)
			},
			// 图片预览
			seeimg(index) {
				console.log(index);
				// uni.previewImage({
				// 	urls: this.img1
				// });
				console.log(this.img1);
				uni.previewImage({
					urls:this.img1,
					current:index,
					loop:true
				})
			},
			// 选择图片2
			choosefrom2() {
				if(this.img2.length<4){
					var _this = this
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							_this.img2.push(res.tempFilePaths[0])
							
						}
					})
				}else{
					uni.showToast({
						icon:'none',
						title:'上传已达到限制'
					})
				}
				
			},
			// 删除图片2
			deletImg2(index) {
				this.img2.splice(index,1)
			},
			// 图片预览2
			seeimg2(index) {
				console.log(index);
				console.log(this.img2);
				uni.previewImage({
					urls:this.img2,
					current:index,
					loop:true
				})
			},
			// 选择图片3
			choosefrom3() {
				if(this.img3.length<4){
					var _this = this
					uni.chooseImage({
						count: 1,
						sizeType: ['original', 'compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							_this.img3.push(res.tempFilePaths[0])
							
						}
					})
				}else{
					uni.showToast({
						icon:'none',
						title:'上传已达到限制'
					})
				}
				
			},
			// 删除图片3
			deletImg3(index) {
				this.img3.splice(index,1)
			},
			// 图片预览3
			seeimg3(index) {
				console.log(index);
				console.log(this.img3);
				uni.previewImage({
					urls:this.img3,
					current:index,
					loop:true
				})
			},

			// 选择气表照片

			changeImg(ret) {
				var that = this;
				that.ret = ret
				that.$refs.cpimg._changImg()

			},
			cpimgOk(file) {
				let that = this
				var ret = that.ret
				uni.showLoading({
					title: '上传中...'
				})
				uni.uploadFile({
					url: that.$fileImg + '/common/upload',
					filePath: file[0],
					name: 'file',
					formData: {
						token: that.token
					},
					success(res1) {
						let dataPath = JSON.parse(res1.data)
						if (dataPath.code == 1) {
							if (ret == '燃气表') {
								that.fileImg1 = dataPath.data.url
								that.img1 = file[0]
								// console.log(111)
							}
							if (ret == '燃气火点') {
								that.fileImg2.push(dataPath.data.url)
								that.img2.push(file[0])
							}
							if (ret == '资料') {
								that.fileImg3.push(dataPath.data.url)
								that.img3.push(file[0])
							}
							if (ret == '其他') {
								that.fileImg4 = dataPath.data.url
								that.img4 = file[0]
							}
						}
						uni.hideLoading()
					},
					fail: () => {
						uni.hideLoading()
						uni.showToast({
							title: '上传失败'
						})
					}
				});


			},

			cpimgErr(e) {
				uni.showToast({
					title: '上传失败',
					icon: 'none'
				})
				console.log(e)
			},

			textChange(e) {
				if (e.detail.cursor >= 200) {
					uni.showToast({
						title: '最多可以输入200个字',
						icon: 'none'
					})
				}
				this.textNumber = e.detail.cursor
			},
			// 获取品牌列表
			getBrandList() {
				let that = this
				that.$request.request({
					url: '/staff/brand_list',
					method: 'POST',
					data: {
						token: that.token
					}
				}).then(res => {
					that.options = res.data.data
				})
				that.$request.request({
					url: '/staff/power_list',
					method: 'POST',
					data: {
						token: that.token
					}
				}).then(res => {
					that.options1 = res.data.data
				})
			},
			// 提交保存
			userPost() {

				console.log(this.last_check.staff_name)

				let that = this
				that.options.forEach(item => {
					if (item.label == that.user_info.brand_name) {
						that.brandId = item.id
					}
				})
				that.options1.forEach(item => {
					if (item.label == that.user_info.power_name) {
						that.powerId = item.id
					}
				})
				if (that.brandId == '') {
					uni.showToast({
						title: '请选择品牌',
						icon: 'none'
					})
					return
				}
				if (that.powerId == '') {
					uni.showToast({
						title: '请选择实际功率',
						icon: 'none'
					})
					return
				}
				if (that.img1 == '') {
					uni.showToast({
						title: '请上传燃气表照片',
						icon: 'none'
					})
					return
				}
				if (that.img2.length < 2) {
					uni.showToast({
						title: '请上传2张燃气火点照片',
						icon: 'none'
					})
					return
				}
				if (that.img3.length < 4) {
					uni.showToast({
						title: '请上传4张资料照片',
						icon: 'none'
					})
					return
				}
				if (that.img4 == '') {
					uni.showToast({
						title: '请上传其他照片',
						icon: 'none'
					})
					return
				}
				if (that.isChecked == false) {
					that.isCheckedNum = '0'
				} else {
					that.isCheckedNum = '1'
				}
				if (that.isChecked1 == false) {
					that.isCheckedNum1 = '0'
				} else {
					that.isCheckedNum1 = '1'
				}
				if (that.isChecked2 == false) {
					that.isCheckedNum2 = '0'
				} else {
					that.isCheckedNum2 = '1'
				}

				var imgs2 = ''
				var imgs3 = ''
				that.fileImg2.forEach(item => {
					imgs2 += item + ','
				})
				that.fileImg3.forEach(item => {
					imgs3 += item + ','
				})
				that.$request.request({
					url: '/staff/check_submit',
					method: 'POST',
					data: {
						member_id: that.user_info.id,
						token: that.token,
						brand: that.brandId,
						power: that.powerId,
						meter_base_num: that.user_info.meter_base_num,

						qibiao_img: that.fileImg1,
						dianhuo_img: imgs2,
						qimi_img: imgs3,
						success_img: that.fileImg4,
						danger_id: this.danger_id,
						is_receive: that.isCheckedNum,
						is_safe: that.isCheckedNum1,
						mark: that.autoText
					}
				}).then(res => {
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						that.flag = true
						that.searchIpt = ''
					}
				})
			},
			danger() {

				if (this.img1 != '') {
					uni.setStorage({
						key: 'img1',
						data: this.img1
					})
				}

				if (this.img2.length > 0) {
					uni.setStorage({
						key: 'img2',
						data: this.img2
					})
				}

				if (this.img3.length > 0) {
					uni.setStorage({
						key: 'img3',
						data: this.img3
					})
				}

				if (this.img4 != '') {
					uni.setStorage({
						key: 'img4',
						data: this.img4
					})
				}

				if (this.autoText != '') {
					uni.setStorage({
						key: 'bztext',
						data: this.autoText
					})
				}


				uni.navigateTo({
					url: '../securityCheck/dangerReport?id=' + this.last_check.member_id + '&type=' + '5' +
						'&socont=' + this.searchIpt
				})

			},
			close() {
				uni.navigateTo({
					url: '../index/index'
				})
				uni.removeStorage({
					key: 'img1'
				})
				uni.removeStorage({
					key: 'img2'
				})
				uni.removeStorage({
					key: 'img3'
				})
				uni.removeStorage({
					key: 'img4'
				})
				uni.removeStorage({
					key: 'bztext'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.addform-items {
		display: flex;
		align-items: center;
	
		.form-img {
			width: 60rpx !important;
			height: 60rpx !important;
			margin-right: 20rpx;
		}
		.delet {
			position: absolute;
			top: -8rpx;
			right: 4rpx;
			width: 28rpx ;
			height: 28rpx ;
			z-index: 10;
		}
	
		.add {
			width: 60rpx;
			height: 60rpx;
			border: 1rpx solid #DDDDDD;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.content {
		.ipts {
			background-color: #fff;
			margin-bottom: 20rpx;

			.liaison {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0rpx 32rpx;
				height: 100rpx;
				align-items: center;

				.left {
					display: flex;
					align-items: center;

					.shuxian {
						width: 8rpx;
						height: 28rpx;
						background: #003690;
						opacity: 1;
						border-radius: 200rpx;
						margin-right: 10rpx;
					}

					.name {
						font-size: 28rpx;
						font-family: Source Han Sans SC;
						font-weight: 500;
						color: #333333;
						margin-right: 10rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #777777;
					}
				}

				.right {
					display: flex;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}

					.phone {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #555555;
					}
				}
			}
		}

		.info-item {
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// height: 72rpx;
			width: 100%;
			height: 100rpx;
			padding: 0rpx 32rpx;
			align-items: center;
			background-color: #fff;
			font-size: 24rpx;
			color: #333;
			border-bottom: 1rpx solid #DDDDDD;

			image {
				width: 32rpx;
				height: 32rpx;
			}

			input {
				flex: 1;
				text-align: right;
			}

			.dot {
				width: 8rpx;
				height: 8rpx;
				background-color: #003690;
				border-radius: 50%;
				margin-right: 10rpx;
			}

			.danger-img {
				position: relative;

				.updeletes {
					position: absolute;
					top: -20rpx;
					right: -20rpx;
					width: 40rpx;
					height: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					z-index: 88;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box2 {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 100%;
						height: 100%;
						opacity: 1;
					}
				}
			}

			.info-item-left {
				display: flex;
				align-items: center;
				font-size: 28rpx;
			}
		}

		.hengxian {
			width: 700rpx;
			height: 2rpx;
			background-color: #eee;
			margin: 20rpx auto;
		}

		.place-class {
			font-size: 28rpx;
			color: #999;
		}

		.btn {
			width: 646rpx;
			height: 80rpx;
			margin: 74rpx auto;
			text-align: center;
			line-height: 80rpx;
			border-radius: 40rpx;
			background-image: linear-gradient(to bottom, #2366D5, #001B48);
			font-size: 32rpx;
			color: #E5EFFE;
		}

		.btns {
			position: fixed;
			bottom: 0;
			display: flex;
			width: 100%;
			z-index: 333;

			.btn1 {
				width: 50%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 24rpx;
			}

			.consel {
				background-color: #e9e9e9;
				color: #777;
			}

			.save {
				background-color: #003690;
				color: #fff;
			}
		}

		.btn:active {
			background: rgba(0, 0, 0, 0.4);
		}

		.zhanwei {
			height: 250rpx;
		}

		.record {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #003690;
			font-size: 32rpx;
			// padding-top: 20rpx;
			padding: 0rpx 0rpx;
			height: 100rpx;
			align-items: center;
			border-bottom: 1rpx solid #DDDDDD;
			

			.right {
				width: 394rpx;
				height: 52rpx;
				background: #F2F2F2;
				opacity: 1;
				border-radius: 50rpx;
				padding:  0 10rpx 0 15rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			image {
				width: 32rpx;
				height: 32rpx;
				margin: 0 20rpx 0 30rpx;
			}

			span {
				font-weight: 700;
			}
		}

		.record-item {
			display: flex;
			justify-content: space-between;
			padding: 10rpx 30rpx;
			border-bottom: 2rpx solid #eee;

			.record-item-left {
				display: flex;
				align-items: center;

				.shu {
					width: 8rpx;
					height: 28rpx;
					background-color: #003690;
					border-radius: 8rpx;
				}

				.title {
					font-size: 32rpx;
					color: #333;
					font-weight: 500;
					margin: 0 10rpx;
				}

				.time {
					font-size: 24rpx;
					color: #777;
				}
			}

			.record-item-right {
				display: flex;
				align-items: center;

				.dianhua {
					width: 28rpx;
					height: 28rpx;
				}

				.zhankai {
					width: 36rpx;
					height: 36rpx;
				}

				.title {
					font-size: 32rpx;
					color: #555;
					font-weight: 500;
					margin: 0 10rpx;
				}
			}
		}

		.supplement {
			margin: 20rpx 24rpx;
			background-color: #fff;
			position: relative;
			overflow: hidden;

			.explain {
				.textArea {
					min-height: 142rpx;
					padding: 14rpx 30rpx;
					font-size: 32rpx;
					text-align: left;
					color: rgba(187, 187, 187, 0.84);
				}
			}

			.suppBottom {
				.danger-img {
					position: relative;
					margin-left: 50rpx;
					margin-bottom: 0rpx;
					width: 68rpx;
					height: 68rpx;
					float: left;

					image {
						width: 36rpx;
						height: 36rpx;
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translate(-50%, -50%);
					}
				}

				.num {
					float: right;
					margin-right: 26rpx;
				}
			}
		}
	}
</style>
